$(function(){
	$("#userType,#adduserType,#edituserType").combobox({
		data:[{"id":"0","text":"会员"},{"id":"1","text":"普通用户"}],
		valueField:'id',  
		textField:'text'
	})
	$("#userDatagrid").datagrid({
		data:{
			"rows":[
			 {"userId":"111","userName":"的说法","userType":"0"},
			 {"userId":"112131","userName":"速度范围","userType":"1"}
			 ]
		},
		//data:{"rows":data_json},
	    fit:true,
	    toolbar:'#userTolbar',
	    fitColumns:true,
	    singleSelect:true,
	    columns:[[  
	        {field:'userId',title:'ID',width:100,align:"center"},
	        {field:'userName',title:'用户名',width:100,align:"center"}, 
	        {field:'userType',title:'用户类型',width:40,align:"center",
	        	formatter:function(value,row,index){
	        		if('0' == value){
	        			return '会员';
	        		}
	        		if('1' == value){
	        			return '普通用户';
	        		}
	        	}	
	        },  
	        {field:'operation',title:'操作',width:100,align:"center",
	        	formatter:function(value,row,index){
	        		return " <a  href='#' onclick=editRow("+index+");  >编辑</a> "+
	                  " <a  href='#' onclick=deleteRow('"+row.userId+"'); >删除</a> ";
	        	}
	        	
	        },
	    ]]  
	
	});
	
	$("#addDialog").dialog({
		title: '新增用户信息',  
	    width: 310,  
	    height:330,  
	    closed: true,  
	    cache: false,    
	    modal: true ,
	    buttons:[{
			text:'保存',
			handler:function(){
				/*$.ajax({
					type : 'post',
				//	url : $WEB_ROOT_PATH+'',
					async : false,
					//data:{'hr':[$.toJSON(data)]},
					dataType : 'json',
					success:function(result){
					},
				});*/
			}
		},{
			text:'关闭',
			handler:function(){
				$("#addDialog").dialog("close");
			}
		}]
	});
	
	$("#editDialog").dialog({
		title: '编辑用户信息',  
	    width: 310,  
	    height:330,  
	    closed: true,  
	    modal: true ,
	    buttons:[{
			text:'保存',
			handler:function(){
				/*$.ajax({
					type : 'post',
				//	url : $WEB_ROOT_PATH+'',
					async : false,
					//data:{'hr':[$.toJSON(data)]},
					dataType : 'json',
					success:function(result){
					},
				});*/
			}
		},{
			text:'关闭',
			handler:function(){
				$("#editDialog").dialog("close");
			}
		}]
	})
})

function doAdd(){
	$("#addDialog").dialog("center");
	$("#addDialog").dialog("open");
	$("#addDialogForm").form("clear");
}

function editRow(index){
	$("#editDialog").dialog("center");
	$("#editDialog").dialog("open");

	$('#userDatagrid').datagrid("selectRow",index);
	var row = $('#userDatagrid').datagrid("getSelected");
	if(!row){
		$('#userDatagrid').datagrid("selectRow",index);
		row = $('#userDatagrid').datagrid("getSelected");
	}
	$("#edituserId").val(row.userId);
	$("#edituserName").val(row.userName);
	$("#edituserType").combobox("setValue",row.userType);
}

function deleteRow(id){
	$.messager.confirm('提示', '确认删除吗？',function(){
		$.post($WEB_ROOT_PATH+"", {'id':id},function(result){
		});
	});
}

function doSearch(){
	
}